void B2Tgive(void);
void B2Tpop(prec rad, prec dP);
void B2TFinal(void);

void B2Tgive(void) {

	prec rad, dP, r;
	int i, k, l, j;
	prec Ur = 0.0;
	NBcount = NBcount+1;
	for(i= 0; i<=(nMolecules-2); i++) {
		for(j =i+1; j<=(nMolecules-1); j++) {
			k = 2;
			l = 2;
			rad = radius(i,j, k, l);

			for(k = 0; k<=2; k++) {
				for(l = 0; l<=2; l++) {
					r = radius(i, j, k, l);
					dP = cpuEnergy(r, i, j, k, l);
					Ur = Ur +dP;
				}
			}
			B2Tpop(rad, Ur);
			Ur = 0.0;
		}
	}
}


void B2Tpop(prec rad, prec Ur) {
	//printf("rad = %lf \n Ur = %12.10e\n", rad, Ur);
	int bin;
	prec db = 0.05;
	bin = (int)(rad/db);
	int k = bin;
	//printf("bin = %d\n", bin);
	B2T[k] = B2T[k] + Ur;
}


void B2TFinal(void) {

	int bin, T;
	prec Rij, t1, t2, et;
	prec db = 0.05;
	T = (int)(box.x/2/db);
	//create file to export to excel
	for (bin = 0; bin <=T-1; bin ++) {
		Rij = db*(double)bin+0.5*db;
		//printf("Rij = %lf\n", Rij);
		t1 = B2T[bin]/(-1*BOLTZMANN_C*tempK);
		printf("bin pop = %12.10e\n", B2T[bin]);
		et = exp(t1);
		t2 = et -1;
		printf("t1 = %12.10e\nt2 = %12.10e\net = %lf\n", t1, t2, et);
		B2T[bin] = t2*Rij*Rij*db*1e-30;
		printf("bin %d = %12.10e\n", bin, B2T[bin]);
		FB2T += B2T[bin];
	}
	
	FB2T *= -2*PI;
	printf("FB2T = %12.10e\n", FB2T);
}



